<template>
	<view class="" style="padding-bottom: 150rpx;">
		<view class="flexcolumn" v-if="list.data.length==0">
			<view class="placeholderimage" style="margin-top: 200rpx;"></view>
			<view class="xiaohui margin_top main_size">暂无数据</view>
		</view>
		<view class="mainpadding_top ffffff"  v-for="item in list.data" @click="jumpdetail('/pages_piaoquan/piaoquanxq?id=',item.id)">
			<view class="flexstart xiahuaxian">
				<image :src="item.user.avatar_text" class="radius" style="width: 90rpx;height: 90rpx;min-width: 90rpx;" mode=""></image>
				<view class="margin_left2" style="width: 100%;">
					<view class="titletext xiaohei fonweight">{{item.user.nickname}}</view>
					<view class="xiaohei ershil margin_top2">{{item.title}}</view>
					<view class="xiaohui ershil margin_top2 lianghang">{{item.content}}</view>
					<view class="flexleft flex_wrap">
						<view class="sanshis flexcenter" v-for="(ite,ind) in item.images_text" :key="ind">
							<view class="margin_top2" style="width: 180rpx;height: 180rpx;">
								<image :src="ite" class=" radius" style="width: 100%;height: 100%;" mode=""></image>
							</view>
						</view>
					</view>
					<view class=" flexbetween margin_top2">
						<view class="xiaohui strongtext">{{item.createtime_text}}</view>
						<view class="flexright">
							<u-icon name="chat" color="#999" size="20"></u-icon>
							<view class="xiaohui strongtext margin_left1">{{item.comment_num}}</view>
						</view>
					</view>
				</view>
			</view>
			<template v-if="item.userdtjl">
				<view class="flexbetween margin_top2">
					<view class="">
						<view class="xiaohei titletext fonweight">中奖截图</view>
						<view class="margin_top xiaohuang ershil" v-if="item.userdtjl.apply_status==1">平台审核中</view>
						<view class="margin_top xiaolv ershil" v-if="item.userdtjl.apply_status==2">审核通过，奖励{{item.userdtjl.jl_price}}金币</view>
						<view class="margin_top xiaohong ershil" v-if="item.userdtjl.apply_status==3">审核失败</view>
					</view>
					<image :src="item.userdtjl.image_text" class="listleftimg" mode="" @click.stop="lbtpriview(0,[item.userdtjl.image_text])"></image>
				</view>
				<view class="xiaohui ershil margin_top2" v-if="item.userdtjl.apply_bz">审核备注：{{item.userdtjl.apply_bz}}</view>
			</template>
			<view class="flexright margin_top">
				<view class="borderh flexleft" @click.stop="jumpdetail('/pages_mypage/fabusq?id=',item.id)">
					<u-icon name="edit-pen" color="#999" size="16"></u-icon>
					<view class="xiaohui ershil">编辑</view>
				</view>
				<view class="borderh flexleft margin_left2" @click.stop="delItem(item.id,'/api/Userdtcl/delUserDt')">
					<u-icon name="trash" color="#999" size="16"></u-icon>
					<view class="xiaohui ershil">删除</view>
				</view>
				<template v-if="Number(userdtjl)">
					<view class="borderhuang flexleft margin_left2" v-if="item.userdtjl==null" @click.stop="currentid=item.id;show=true">
						<u-icon name="integral" color="#ff8506" size="16"></u-icon>
						<view class="xiaohuang ershil">申请中奖金币</view>
					</view>
					<view class="borderhuang flexleft margin_left2" v-if="item.userdtjl && item.userdtjl.apply_status==1">
						<u-icon name="integral" color="#ff8506" size="16"></u-icon>
						<view class="xiaohuang ershil">正在申请中</view>
					</view>
				</template>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="jumpurl('/pages_mypage/fabusq')">添加</view>
		</view>
		<u-popup mode="center" round="10" :show="show" @close="show=false">
			<view class="mainpadding ffffff radius" style="min-width: 600rpx;">
				<view class="textcenter xiaohei titletext">上传中奖截图</view>
				<view class="weisc margin_top7 flexcolumn" v-if="image==''" @click="uploadImg">
					<u-icon name="camera" color="#ff8506" size="60"></u-icon>
					<view class="xiaohuang ershiba">点击上传</view>
				</view>
				<view class="margin_top7" v-else @click="uploadImg">
					<image :src="image_text" style="width: 600rpx;height: 400rpx;border-radius: 20rpx;" mode=""></image>
				</view>
				<view class="ershil xiaohuang textcenter margin_top7">注：请上传中奖截图，只能上传一次不可重复上传！</view>
				<view class="flexbetween">
					<view class="czbtn flexcenter margin_top" @click="show=false">暂不提交</view>
					<view class="ljcz flexcenter margin_top" @click="submit()">确认上传</view>
				</view>
			</view>
		</u-popup>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show:false,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				currentid:"",
				image:"",
				image_text:"",
				userdtjl:0,
				modal:{
					modalShow:false,
					title:"",
				},
				currentapi:"",
			}
		},
		onLoad() {
			this.getsystem()
		},
		onShow() {
			this.init()
		},
		watch:{
			show(newval){
				if(newval){
					this.image=""
					this.image_text = ""
				}
			}
		},
		methods: {
			delItem(id,url){
				this.currentapi = url
				this.currentid = id
				this.modal.title="是否确认删除当前晒票？"
				this.modal.modalShow = true
			},
			modalSure(){
				if(this.modal.title=="是否确认删除当前晒票？"){
					this.delOrder()
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			delOrder(){
				httpRequest.request(this.currentapi, 'POST', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			getsystem(){
				httpRequest.request('/api/index/getConfigInfoItem', 'POST', {
					pidtype:"otherset",
					type:"userdtjl",
				}).then(res => {
					this.userdtjl = res.data
				})
			},
			submit(){
				if(this.image==""){
					httpRequest.toast("请上传中奖截图")
					return false
				}
				let data = {
					id:this.currentid,
					image:this.image,
				}
				this.show = false
				httpRequest.request('/api/userdtcl/addUserDtJl', 'GET', data).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			uploadImg(value, upImgs,upImgs_text) {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs,upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs,upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, upImg,upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.image = res.url;
					this.image_text = image_item
					
				}).catch(err => {});
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/Userdtcl/myUserDtIndex', 'GET', {
					page: page || 1,
					limit: 12,
				}).then(res => {
					uni.stopPullDownRefresh()
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-transition{
		z-index: 10 !important;
	}
	.ljcz {
		width: 258rpx;
		height: 76rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		background-color: #FF7510;
		border: 2rpx solid #FF7510;
		border-radius: 10rpx;
		color: #FFFFFF;
	}
	
	.czbtn {
		width: 258rpx;
		height: 76rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		background-color: #fff2e8;
		border: 2rpx solid #FF7510;
		border-radius: 10rpx;
		color: #FF7510;
	}
.borderh{
	padding: 10rpx 20rpx;
	border: 1rpx solid #999;
	border-radius: 10rpx;
}
.borderhuang{
	padding: 10rpx 20rpx;
	border: 1rpx solid #ff8506;
	border-radius: 10rpx;
}
.weisc{
	background-color: #fff6f0;
	width: 600rpx;
	height: 400rpx;
	border: 1rpx dashed #ff8506;
	border-radius: 20rpx;
}
</style>
